package com.xiaoxx.coin.impl.futures;

import com.alibaba.fastjson.JSONObject;
import com.xiaoxx.coin.enums.HttpMethodEnum;
import com.xiaoxx.coin.handler.RequestHandler;
import com.xiaoxx.coin.po.*;
import com.xiaoxx.coin.po.res.ExchangeInfoResponse;
import com.xiaoxx.coin.po.res.TakerBuySellVolRespone;
import com.xiaoxx.coin.po.res.TickerPrice24Response;
import com.xiaoxx.coin.po.res.TickerPriceResponse;

import java.util.LinkedHashMap;
import java.util.List;

public  class Market {
    private String baseUrl;
    private String productUrl;
    private RequestHandler requestHandler;
    private boolean showLimitUsage;

    public Market(String productUrl, String baseUrl, String apiKey, boolean showLimitUsage, ProxyAuth proxy) {
        this.baseUrl = baseUrl;
        this.productUrl = productUrl;
        this.requestHandler = new RequestHandler(apiKey, proxy);
        this.showLimitUsage = showLimitUsage;
    }
    public String getBaseUrl() {
        return this.baseUrl;
    }
    private final String EXCHANGE_INFO = "/v1/exchangeInfo";

    public ExchangeInfoResponse exchangeInfo() {
        String s = requestHandler.sendPublicRequest(productUrl, EXCHANGE_INFO, null, HttpMethodEnum.GET, showLimitUsage);
        return JSONObject.parseObject(s, ExchangeInfoResponse.class);
    }

    private final String TICKER_SYMBOL = "/v1/ticker/price";
    public List<TickerPriceResponse> tickerPrice(LinkedHashMap<String, Object> parameters) {
        String s = requestHandler.sendPublicRequest(productUrl, TICKER_SYMBOL, parameters, HttpMethodEnum.GET, showLimitUsage);
        return JSONObject.parseArray(s, TickerPriceResponse.class);
    }
    private final String TICKER_SYMBOL_24 = "/v1/ticker/24hr";
    public List<TickerPrice24Response> tickerPrice24(LinkedHashMap<String, Object> parameters) {
        String s = requestHandler.sendPublicRequest(productUrl, TICKER_SYMBOL_24, parameters, HttpMethodEnum.GET, showLimitUsage);
        return JSONObject.parseArray(s, TickerPrice24Response.class);
    }
    private final String TAKE_BUY_SELL_VOLUME = "/futures/data/takerlongshortRatio";

    public List<TakerBuySellVolRespone> takerBuySellVol(LinkedHashMap<String, Object> parameters) {
        String s = requestHandler.sendPublicRequest(getBaseUrl(), TAKE_BUY_SELL_VOLUME, parameters, HttpMethodEnum.GET, showLimitUsage);
        return JSONObject.parseArray(s, TakerBuySellVolRespone.class);
    }

}
